package weaver.jobs.zswy;

import com.alibaba.fastjson.JSONObject;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

/***
 * 销假申请流程
 * @author lingman
 * 2018-10-11
 */
public class KQ_xjsq implements Action {
	private String url="http://10.20.82.165:18010/RESTService/SaveOrUpdate";
	@Override
	public String execute(RequestInfo request) {
		NewRestServiceUtil nUtil = new NewRestServiceUtil();
		String requestid = request.getRequestid();
		String tablename = request.getRequestManager().getBillTableName();
		writeLog(">>>>>KQ_xjsq>>>requestid="+requestid);
		try{
			RecordSet rs = new RecordSet();
			rs.execute("select * from "+tablename+" where requestid='"+requestid+"'");
			rs.next();
			//员工工号
			String EmpNo = Util.null2String(rs.getString("xjrygh"));
			//开始日期。格式为yyyy-MM-dd
			String qsrq = Util.null2String(rs.getString("qsrq"));
			//截止日期。格式为yyyy-MM-dd
			String jsrq = Util.null2String(rs.getString("jsrq"));
			//开始时间。格式为HH:mm
			String qssj = Util.null2String(rs.getString("qssj"));
			//截止时间。格式为HH:mm
			String jssj = Util.null2String(rs.getString("jssj"));
			//销假方式
			String xjfs = "7";
			//请假类别编号
			String LeaveType = Util.null2String(rs.getString("xjlb"));
			//备注说明
			String remark = Util.null2String(rs.getString("xjsy"));
			writeLog("查询结果：EmpNo="+EmpNo+",qsrq="+qsrq+",jsrq="+jsrq+",qssj="+qssj+",jssj="+jssj);
			String params="{\"FunID\":\""+"KQ033001Cancel"+"\",\"Language\":1,\"Data\":{\"EmpNo\":\""+EmpNo+"\",\"YYMMDD\":\""+qsrq+"\",\"EndYYMMDD\":\""+jsrq+"\",\"BeginTime\":\""+qssj+"\",\"EndTime\":\""+jssj+"\",\"Flag\":7},\"IsCommitConfirmAtOnce\":false}";
			writeLog("params："+params);
			String res = nUtil.dopostMethod(url, params);
			writeLog("res："+res);
			if(!"".equals(res)){
				JSONObject resJson = JSONObject.parseObject(res);
				String status = resJson.getString("Success");
				String msg = resJson.getString("Message");
				if(!"true".equals(status)){
					request.getRequestManager().setMessageid( "111111" );
					request.getRequestManager().setMessagecontent( "接口返回信息:"+msg );
					return Action.FAILURE_AND_CONTINUE;
				}else{
					return Action.SUCCESS;
				}
			}else {
				writeLog("流程："+requestid+",销假申请流程接口执行失败！接口调用失败。");
				return Action.FAILURE_AND_CONTINUE;
			}

		}catch (Exception e) {
			writeLog("流程："+requestid+",销假申请流程接口执行失败！！！"+e.getLocalizedMessage());
			return Action.FAILURE_AND_CONTINUE;
		}
	}
	
	public void writeLog(Object obj) {
		if(true){
			new BaseBean().writeLog(this.getClass().getName(), obj);
		}
	}

}
